import unittest
from alg import maxProfit
from gen import generate_prices, generate_fee

class TestMaxProfit(unittest.TestCase):
    def test_empty_prices(self):
        self.assertEqual(maxProfit([], 2), 0)
    
    def test_single_price(self):
        self.assertEqual(maxProfit([5], 1), 0)
    
    def test_two_prices_profit(self):
        self.assertEqual(maxProfit([1, 5], 2), 2)
    
    def test_two_prices_no_profit(self):
        self.assertEqual(maxProfit([5, 1], 2), 0)
    
    def test_multiple_transactions(self):
        prices = [1, 3, 2, 8, 4, 9]
        fee = 2
        # 交易1: 1买,8卖,利润5; 交易2: 4买,9卖,利润3; 总利润8
        self.assertEqual(maxProfit(prices, fee), 8)

    def test_random_data(self):
        for _ in range(10):
            prices = generate_prices(20)
            fee = generate_fee()
            result = maxProfit(prices, fee)
            self.assertTrue(isinstance(result, int))
            self.assertGreaterEqual(result, 0)

if __name__ == '__main__':
    unittest.main()  